﻿Imports Entities
Public Class PagosDAL
    Public Shared Function Create(ByVal zObject As PAGOS) As PAGOS
        Try
            Using bd As New gas_gasdesuvecinoEntities
                bd.PAGOS.Add(zObject)
                bd.SaveChanges()
                Return zObject
            End Using
        Catch ex As Exception
            Debug.Print("PagosDAL.Create() " + ex.Message)
            Return Nothing
        End Try
    End Function

    Public Shared Function List() As List(Of PAGOS)
        Try
            Using bd As New gas_gasdesuvecinoEntities
                Return bd.pagos.ToList
            End Using
        Catch ex As Exception
            Debug.Print("PagosDAL.List() " + ex.Message)
            Return Nothing
        End Try
    End Function
   
    Public Shared Function ListByTipoPago(ByVal zTipoPago As String) As List(Of PAGOS)
        Try
            Using bd As New gas_gasdesuvecinoEntities
                Dim query = From rec In bd.PAGOS
                          Where rec.TIPO = zTipoPago
                            Select rec

                Return query.ToList
            End Using
        Catch ex As Exception
            Return Nothing
        End Try
    End Function
   
    Public Shared Function SearchById(ByVal zId As Long) As PAGOS
        Try
            Using bd As New gas_gasdesuvecinoEntities
                Return bd.pagos.Find(zId)
            End Using
        Catch ex As Exception
            Debug.Print("PagosDAL.SearchById() " + ex.Message)
            Return Nothing
        End Try
    End Function
   

    Public Shared Function Update(ByVal zPago As PAGOS) As PAGOS
        Try
            Using bd As New gas_gasdesuvecinoEntities
                Dim query = (From rec In bd.PAGOS
                           Where rec.PAGO = zPago.PAGO
                           Select rec).SingleOrDefault
                query.FORMAPAGO = zPago.FORMAPAGO
                query.MONTO = zPago.MONTO
                query.FECHA = zPago.FECHA
                bd.SaveChanges()
                Return query
            End Using
        Catch ex As Exception
            Return Nothing
        End Try
    End Function
    Public Shared Function Delete(ByVal zPago As PAGOS) As Boolean
        Try
            Using bd As New gas_gasdesuvecinoEntities
                Dim Pag = bd.PAGOS.Find(zPago.PAGO)
                bd.PAGOS.Remove(Pag)
                bd.SaveChanges()
            End Using
            Return True
        Catch ex As Exception
            Return Nothing
        End Try
    End Function
End Class
